import { reactive } from 'vue';
import { useDebounceFn } from '@vueuse/core';

import { FormSchema } from '/@/components/Table';

import { MODE } from '/@/components/CodeEditor';

import { DICT } from '/@/enums/dict';
import {
  ComponentTypeEnum,
  LIST_FIELD_TYPE,
  SEARCH_TYPE,
} from '/@/components/ModelTable/src/types';

// new Function('a', 'b', 'return a + b');
import {
  LabelTypeList,
  UpdateTypeList,
  // LabelWidthList,
  // ContentWidthList,
  PickerDateList,
  StoreTypeList,
  JSCommentForTableForm,
} from './consts';
import { getDictTypeListApi, getDictPageListApi } from '/@/api/admin/dict';
import { getDBListApi } from '/@/api/database/account';

const dictListParam = reactive({ current: 1, size: 100, dictType: '' });

// const isLinkType = ({ values }) => values.fieldType === LIST_FIELD_TYPE.LINK_FIELD_TYPE;
const isFrontFunction = ({ values }) => values.fieldType === LIST_FIELD_TYPE.FUNCTION_FIELD_TYPE;
const isDitcType = ({ values }) => values.fieldType === LIST_FIELD_TYPE.DICT_FIELD_TYPE;
const isSwitchType = ({ values }) => values.fieldType === LIST_FIELD_TYPE.SWITCH_FIELD_TYPE;
const isSearchType = ({ values }) => values.searchType !== SEARCH_TYPE.DISABLED;
// const isOptionsType = ({ values }) => values.fieldType === OPTION_FIELD_TYPE;
const isImgType = ({ values }) => values.fieldType === LIST_FIELD_TYPE.IMG_FIELD_TYPE;

export const titlesSchema: FormSchema[] = [
  {
    field: 'title',
    label: '名称',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入名称',
    },
    colProps: { span: 12 },
  },

  {
    field: 'dataIndex',
    label: '名称编码',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入名称编码',
    },
    colProps: { span: 12 },
  },

  {
    field: 'displayType',
    label: '显示类型',
    component: 'ApiRadioGroup',
    defaultValue: 1,
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.MODEL_DISPLAY_TYPE,
      },
    },
  },
  {
    field: 'fieldType',
    label: '字段类型',
    required: true,
    component: 'ApiSelect',
    defaultValue: 0,
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      placeholder: '请选择字段类型',
      params: {
        type: DICT.FIELD_TYPE,
      },
      getPopupContainer: () => document.body,
    },
    colProps: { span: 12 },
  },
  {
    field: 'dataType',
    label: '数据类型',
    required: true,
    component: 'ApiSelect',
    defaultValue: 10,
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      placeholder: '请选择数据类型',
      params: {
        type: DICT.DATA_TYPE,
      },
      getPopupContainer: () => document.body,
    },
    colProps: { span: 12 },
  },
  {
    field: 'searchType',
    label: '查询设置',
    required: true,
    component: 'ApiSelect',
    defaultValue: 0,
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.SEARCH_TYPE,
      },
      getPopupContainer: () => document.body,
    },
    colProps: { span: 12 },
  },

  {
    required: true,
    field: 'functionName',
    label: '函数名',
    component: 'Input',
    ifShow: isFrontFunction,
  },
  {
    field: 'appDisplayType',
    label: 'app显示类型',
    // required: true,
    component: 'ApiSelect',
    defaultValue: 1,
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.MODEL_DISPLAY_TYPE,
      },
    },
    colProps: { span: 12 },
  },
  {
    field: 'appTitle',
    label: 'app标题',
    // required: true,
    component: 'Select',
    defaultValue: false,
    componentProps: {
      options: [
        { label: '显示', value: true },
        { label: '隐藏', value: false },
      ],
    },
    colProps: { span: 12 },
  },
  {
    field: 'appHeaderLeft',
    label: 'app头部左侧文本',
    // required: true,
    component: 'Select',
    defaultValue: false,
    componentProps: {
      options: [
        { label: '显示', value: true },
        { label: '隐藏', value: false },
      ],
    },
    colProps: { span: 12 },
  },
  {
    field: 'appHeaderRight',
    label: 'app头部右侧文本',
    // required: true,
    component: 'Select',
    defaultValue: false,
    componentProps: {
      options: [
        { label: '显示', value: true },
        { label: '隐藏', value: false },
      ],
    },
    colProps: { span: 12 },
  },
  {
    field: 'appCenter',
    label: 'app内容体',
    // required: true,
    component: 'Select',
    defaultValue: false,
    componentProps: {
      options: [
        { label: '显示', value: true },
        { label: '隐藏', value: false },
      ],
    },
    colProps: { span: 12 },
  },
  {
    field: 'appCenterAfter',
    label: 'app内容体后缀',
    // required: true,
    component: 'Input',

    colProps: { span: 12 },
  },
  {
    field: 'appFooter',
    label: 'app列表底部',
    // required: true,
    component: 'Select',
    defaultValue: false,
    componentProps: {
      options: [
        { label: '显示', value: true },
        { label: '隐藏', value: false },
      ],
    },
    colProps: { span: 12 },
  },

  {
    label: '是否预览',
    field: 'preview',
    component: 'Switch',
    defaultValue: 0,
    componentProps: {
      checkedValue: 1,
      unCheckedValue: 0,
    },
    ifShow: isImgType,
  },
  // ======= 开关 start ==========
  {
    required: true,
    field: 'checkedValue',
    label: '选中时的值',
    component: 'InputNumber',
    ifShow: isSwitchType,
  },

  {
    required: true,
    field: 'unCheckedValue',
    label: '非选中时的值',
    component: 'InputNumber',
    ifShow: isSwitchType,
  },
  {
    field: 'checkedChildren',
    label: '选中时的内容',
    component: 'Input',
    ifShow: isSwitchType,
  },

  {
    field: 'unCheckedChildren',
    label: '非选中时的内容',
    component: 'Input',
    ifShow: isSwitchType,
  },
  // ======= 开关 end ==========

  {
    field: 'displayFormat',
    label: '显示格式',
    component: 'Input',
  },

  {
    field: 'width',
    label: '宽度',
    component: 'InputNumber',
    componentProps: {
      placeholder: '请输入宽度',
    },
    colProps: { span: 12 },
  },

  // {
  //   field: 'routePath',
  //   label: '路由地址',
  //   component: 'Input',
  //   componentProps: {},
  //   colProps: { span: 12 },
  //   ifShow: isLinkType,
  // },
  {
    field: 'event',
    label: '查询配置函数',
    component: 'ButtonCodeEditor',
    defaultValue: JSCommentForTableForm,
    componentProps: {
      mode: 'javascript',
    },
    ifShow: isSearchType,
  },

  {
    field: 'labelSpan',
    label: '标签宽度',
    component: 'Slider',
    componentProps: {
      max: 12,
      min: 1,
      marks: { 6: '6', 12: '12' },
    },
    ifShow: isSearchType,
  },

  {
    field: 'colNum',
    label: '行宽',
    required: false,
    component: 'Slider',
    componentProps: {
      max: 24,
      min: 1,
      marks: { 12: '12', 24: '24' },
    },
    ifShow: (data) => isSearchType(data),
  },
  {
    field: 'ellipsis',
    label: '超出是否省略',
    component: 'Switch',
    defaultValue: true,
    componentProps: {},
    colProps: { span: 12 },
  },
  {
    field: 'isSort',
    label: '是否排序',
    component: 'Switch',
    defaultValue: 0,
    componentProps: {
      checkedValue: 1,
      unCheckedValue: 0,
    },
    colProps: { span: 12 },
  },
  // SEARCH_TYPE
  {
    field: 'dictType',
    label: '字典类型',
    component: 'ApiSelect',
    componentProps: {
      showSearch: true,
      api: async (v) => {
        const { records } = await getDictPageListApi(v);
        records.forEach((el) => {
          el.label = `${el.description}(${el.dictType})`;
          el.value = el.dictType;
        });
        return records;
      },
      params: dictListParam,

      onSearch: useDebounceFn((v) => {
        console.log(
          '%cv===>300',
          'background: rgb(24, 197, 247,.6); color: #ff5024; font-size:18px;font-weight:700',
          v,
        );
        dictListParam.dictType = v;
      }, 200),
    },
    colProps: { span: 12 },
    ifShow: isDitcType,
  },
  {
    field: 'params',
    label: '参数',
    defaultValue: '{}',
    component: 'InputTextArea',
    componentProps: {
      rows: 4,
    },
    ifShow: isFrontFunction,
  },
  {
    required: false,
    field: 'helpMessage',
    label: '说明/帮助',
    slot: 'helpMessage',
    component: 'InputTextArea',
    colProps: { lg: 24, md: 24 },
  },
];
export const searchConfig: FormSchema[] = [];

export const classificationColumns = async (fieldType: number): Promise<any[]> => {
  const opList = await getDictTypeListApi({
    type: DICT.CONDITION_SYMBOL,
  });
  const comItems = [
    {
      label: '字段名',
      field: 'field',
      class: 'w-30',
      component: 'Input',
      componentProps() {
        return { placeholder: '请输入字段名' };
      },
    },
    {
      label: '符号',
      field: 'op',
      class: 'w-20',
      component: 'Select',
      componentProps() {
        return {
          placeholder: '请选择符号',
          options: opList,
        };
      },
    },
    {
      label: '标签编码',
      field: 'value',
      class: 'w-30',
      component: 'Input',
      componentProps() {
        return { placeholder: '请输入编码' };
      },
    },
  ];
  switch (fieldType) {
    case LIST_FIELD_TYPE.IMG_FIELD_TYPE:
      return [
        ...comItems,
        {
          label: '图像网址',
          field: 'label',
          component: 'Input',
          componentProps() {
            return { placeholder: '请输入图像网址' };
          },
        },
      ];
    case LIST_FIELD_TYPE.LINK_FIELD_TYPE:
      return [
        ...comItems,
        {
          label: '标签',
          field: 'label',
          class: 'w-30',
          component: 'Input',
          componentProps() {
            return { placeholder: '请输入标签' };
          },
        },
        {
          label: '网址',
          field: 'url',
          component: 'Input',
          componentProps() {
            return { placeholder: '请输入网址' };
          },
        },
        // {
        //   label: '链接类型',
        //   field: 'labelType',
        //   component: 'Select',
        //   class: 'w-20',
        //   componentProps() {
        //     return { allowClear: true, placeholder: '请选择标签类型', options: LabelTypeList };
        //   },
        // },
        {
          label: '背景色',
          field: 'gbColor',
          class: 'w-20',
          component: 'ColorPicker',
          componentProps() {
            return { placeholder: '请选择背景色' };
          },
        },
        {
          label: '前景色',
          field: 'color',
          class: 'w-20',
          component: 'ColorPicker',
          componentProps() {
            return { placeholder: '请选择前景色' };
          },
        },
      ];
    default:
      break;
  }

  // OPTION_FIELD_TYPE MIX_FIELD_TYPE
  return [
    ...comItems,
    {
      label: '标签',
      field: 'label',
      class: 'w-40',
      component: 'Input',
      componentProps() {
        return { placeholder: '请输入标签' };
      },
    },
    {
      label: '标签类型',
      field: 'labelType',
      component: 'Select',
      class: 'w-35',
      componentProps() {
        return {
          style: 'width:100%',
          allowClear: true,
          placeholder: '请选择标签类型',
          options: LabelTypeList,
        };
      },
    },
    {
      label: '背景色',
      field: 'gbColor',
      class: 'w-20',
      component: 'ColorPicker',
      componentProps() {
        return { placeholder: '请选择背景色' };
      },
    },
    {
      label: '前景色',
      field: 'color',
      class: 'w-20',
      component: 'ColorPicker',
      componentProps() {
        return { placeholder: '请选择前景色' };
      },
    },
  ];
};

export const relaTableSchema: FormSchema[] = [
  {
    field: 'relaTable',
    label: '关联表',
    component: 'Input',
    componentProps: {},
  },
  {
    field: 'relaField',
    label: '关联字段',
    component: 'Input',
    componentProps: {},
  },
  {
    field: 'mainField',
    label: '主表字段',
    component: 'Input',
    componentProps: {},
  },
  {
    field: 'subField',
    label: '子表字段',
    component: 'Input',
    componentProps: {},
  },
  {
    field: 'displayField',
    label: '显示字段',
    component: 'Input',
    componentProps: {},
  },
  {
    field: 'limit',
    label: '条件限制',
    component: 'Input',
    componentProps: {},
  },
  {
    field: 'condition',
    label: '查询条件',
    component: 'InputTextArea',
    componentProps: {},
  },
];
const TARGET_FIELD_TYPE = 5;
const canotAddCustomData = (componentType) => {
  return [
    ComponentTypeEnum.SubTable,
    ComponentTypeEnum.ApiTreeSelect,
    ComponentTypeEnum.Upload,
  ].includes(componentType);
};
// const isSubTable = ({ values }) => values.componentType === ComponentTypeEnum.SubTable;
const isHideField = ({ values }) => values.formModelHiddenType === TARGET_FIELD_TYPE;

const isUpload = ({ values }) => values.componentType === ComponentTypeEnum.Upload;

const isHide = ({ values }) => values.componentType === ComponentTypeEnum.Hide;
// const isDateRange = ({ values }) => values.componentType === ComponentTypeEnum.RangePicker;
const isPassword = ({ values }) => values.componentType === ComponentTypeEnum.InputPassword;
const isTextArea = ({ values }) => values.componentType === ComponentTypeEnum.InputTextArea;
const isSwitch = ({ values }) => values.componentType === ComponentTypeEnum.Switch;
const isNumber = ({ values }) => values.componentType === ComponentTypeEnum.InputNumber;
const isDate = ({ values }) =>
  [ComponentTypeEnum.DatePicker, ComponentTypeEnum.RangePicker].includes(values.componentType);
const isRadioAndCheckbox = ({ values }) =>
  [ComponentTypeEnum.RadioGroup, ComponentTypeEnum.CheckboxGroup].includes(values.componentType);
const isSelect = ({ values }) =>
  [ComponentTypeEnum.ApiSelect, ComponentTypeEnum.ApiTreeSelect].includes(values.componentType);
const isInput = ({ values }) =>
  [ComponentTypeEnum.Input, ComponentTypeEnum.InputTextArea].includes(values.componentType);
const isClear = ({ values }) =>
  [
    ComponentTypeEnum.Input,
    ComponentTypeEnum.ApiSelect,
    ComponentTypeEnum.ApiTreeSelect,
    ComponentTypeEnum.DatePicker,
    ComponentTypeEnum.InputTextArea,
    ComponentTypeEnum.RangePicker,
  ].includes(values.componentType);
const isDBType = ({ values }) =>
  [
    ComponentTypeEnum.ApiSelect,
    ComponentTypeEnum.ApiTreeSelect,
    ComponentTypeEnum.RadioGroup,
    ComponentTypeEnum.CheckboxGroup,
    ComponentTypeEnum.Upload,
    ComponentTypeEnum.SubTable,
  ].includes(values.componentType);

export const formItemSchema: FormSchema[] = [
  {
    field: 'label',
    label: '字段名',
    required: true,
    component: 'Input',
  },
  {
    field: 'field',
    label: '字段名编码',
    required: true,
    component: 'Input',
  },
  {
    field: 'componentType',
    label: '组件类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: getDictTypeListApi,
      allowClear: false,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.COMPONENT_TYPE,
      },
      getPopupContainer: () => document.body,
    },
  },

  /*========= 文本 start=============*/

  {
    field: 'formModelDataType',
    label: '数据类型',
    component: 'ApiSelect',
    componentProps: {
      api: getDictTypeListApi,
      allowClear: false,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.FORM_MODEL_DATA_TYPE,
      },
    },
  },

  {
    field: 'maxlength',
    label: '最大长度',
    component: 'InputNumber',
    ifShow: isInput,
  },
  {
    field: 'rows',
    label: '默认行数',
    component: 'InputNumber',
    ifShow: isTextArea,
  },
  {
    field: 'minRows',
    label: '最小行数',
    component: 'InputNumber',
    ifShow: isTextArea,
  },
  {
    field: 'maxRows',
    label: '最大行数',
    component: 'InputNumber',
    ifShow: isTextArea,
  },

  {
    field: 'showCount',
    label: '字数是否展示',
    component: 'Switch',
    colProps: { span: 12, lg: 12, md: 24 },
    ifShow: isInput,
  },

  /*========= 文本 end =============*/

  /*========= 数字 start =============*/
  // isNumber
  {
    field: 'min',
    label: '最小值',
    component: 'InputNumber',
    ifShow: isNumber,
  },
  {
    field: 'max',
    label: '最大值',
    component: 'InputNumber',
    ifShow: isNumber,
  },
  {
    field: 'step',
    label: '步长',
    component: 'Input',
    ifShow: isNumber,
  },
  {
    field: 'stringMode',
    label: '是否支持小数',
    component: 'Switch',
    ifShow: isNumber,
  },

  /*========= 数字 end =============*/

  /*========= 密码 start =============*/
  {
    field: 'visibilityToggle',
    label: '是否显示切换按钮',
    labelWidth: 175,
    component: 'Switch',
    // itemProps: { labelCol: { span: 6 } },

    ifShow: isPassword,
  },
  /*========= 密码 end =============*/

  /*========= 日期 start =============*/
  {
    field: 'picker',
    label: '选择器类型',
    component: 'Select',
    componentProps: {
      options: PickerDateList,
    },
    ifShow: isDate,
  },

  {
    field: 'format',
    label: '显示格式',
    component: 'Input',
    ifShow: isDate,
  },
  {
    field: 'valueFormat',
    label: '日期格式',
    component: 'Input',
    ifShow: isDate,
  },
  {
    field: 'showTime',
    label: '是否选择时间',
    component: 'Switch',
    colProps: { span: 5, lg: 6, md: 24 },
    ifShow: isDate,
  },
  /*========= 日期 end =============*/

  /*========= 隐藏字段 start =============*/
  {
    field: 'formModelHiddenType',
    label: '隐藏类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.FORM_MODEL_HIDDEN_TYPE,
      },
      getPopupContainer: () => document.body,
    },
    ifShow: isHide,
    colProps: { span: 12 },
  },
  {
    field: 'targetFiled',
    label: '目标字段',
    component: 'Input',
    required: true,
    ifShow: (data) => isHide(data) && isHideField(data),
    colProps: { span: 12 },
  },
  /*========= 隐藏字段 end =============*/

  /*========= 开关 start =============*/

  {
    required: true,
    field: 'checkedValue',
    label: '选中时的值',
    component: 'InputNumber',
    ifShow: isSwitch,
  },

  {
    required: true,

    field: 'unCheckedValue',
    label: '非选中时的值',
    component: 'InputNumber',
    ifShow: isSwitch,
  },
  {
    field: 'checkedChildren',
    label: '选中时的内容',
    component: 'Input',
    ifShow: isSwitch,
  },
  {
    field: 'unCheckedChildren',
    label: '非选中时的内容',
    component: 'Input',
    ifShow: isSwitch,
  },
  /*========= 隐藏字段 end =============*/
  {
    field: 'dataSourceType',
    label: '数据来源',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: async (params) => {
          const ret = await getDBListApi(params);
          ret.forEach((e) => {
            e.connName = `${e.connName} (${e.connCode})`;
          });
          if (!canotAddCustomData(formModel.componentType)) {
            ret.unshift(
              // @ts-ignore
              ...[
                { connName: '资源管理', connCode: '-3' },
                { connName: '数据字典', connCode: '-2' },
                { connName: '固定数据', connCode: '-1' },
              ],
            );
          }

          return ret;
        },
        showSearch: true,
        filterOption: (input: string, option: any) => {
          return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
        immediate: true,
        allowClear: false,
        placeholder: '请选择数据来源',
        labelField: 'connName',
        valueField: 'connCode',
        getPopupContainer: () => document.body,
      };
    },
    ifShow: isDBType,
  },
  // {
  //   field: 'selectType',
  //   label: '选择类型',
  //   component: 'ApiSelect',
  //   componentProps: {
  //     api: getDictTypeListApi,
  //     labelField: 'label',
  //     valueField: 'intValue',
  //     params: {
  //       type: DICT.SELECT_TYPE,
  //     },
  //   },
  //   ifShow: isSelect,
  // },
  /*========= 下拉 start =============*/
  {
    field: 'dictType',
    label: '字典类型',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: async (v) => {
        const { records } = await getDictPageListApi(v);
        records.forEach((el) => {
          el.label = `${el.description}(${el.dictType})`;
          el.value = el.dictType;
        });
        return records;
      },
      params: dictListParam,
      showSearch: true,
      onSearch: useDebounceFn((v) => {
        console.log(
          '%cv===>818： ',
          'background: rgb(24, 197, 247,.6); color: #ff5024; font-size:18px;font-weight:700',
          v,
        );

        dictListParam.dictType = v;
      }, 200),
    },
    ifShow: ({ values }) => values.dataSourceType === '-2',
  },
  {
    field: 'selectType',
    label: '选择类型',
    component: 'ApiSelect',
    defaultValue: 1,
    componentProps: {
      allowClear: false,
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.SELECT_TYPE,
      },
    },
    ifShow: isSelect,
  },
  {
    field: 'isSearch',
    label: '是否可查询',
    component: 'Switch',
    ifShow: isSelect,
    colProps: { span: 5, lg: 12, md: 24 },
  },
  /*========= 下拉 end =============*/

  /*========= 文件上传 sart =============*/
  {
    field: 'accept',
    label: '文件类型',
    component: 'Input',
    ifShow: isUpload,
  },
  {
    field: 'maxSize',
    label: '最大文件(M)',
    component: 'InputNumber',
    ifShow: isUpload,
  },
  {
    field: 'maxNumber',
    label: '最大文件数',
    component: 'InputNumber',
    ifShow: isUpload,
  },

  /*========= 文件上传 end =============*/

  {
    field: 'formModelShowType',
    label: '显示类型',
    component: 'ApiSelect',
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.FORM_MODEL_SHOW_TYPE,
      },
      getPopupContainer: () => document.body,
    },
    ifShow: isRadioAndCheckbox,
    colProps: { span: 12 },
  },

  {
    field: 'allowClear',
    label: '是否可清空',
    component: 'Switch',
    colProps: { span: 5, lg: 12, md: 24 },
    ifShow: isClear,
  },
  {
    field: 'isUnique',
    label: '数据是否唯一',
    component: 'Switch',
    componentProps: {
      checkedValue: 0,
      unCheckedValue: 1,
    },
    colProps: { span: 5, lg: 12, md: 24 },
    ifShow: isInput,
  },
  {
    field: 'updateType',
    label: '读写设置',
    component: 'RadioGroup',
    defaultValue: 1,
    componentProps: {
      options: UpdateTypeList,
    },
  },
];

export const SQLTableSchema = (componentType: ComponentTypeEnum): FormSchema[] => {
  const checkboxItem: FormSchema[] = [
    {
      field: 'showColumn',
      label: '显示列',
      component: 'Input',
      required: true,
      componentProps: {},
    },
    {
      field: 'primaryColumn',
      label: '主键列',
      component: 'Input',
      required: true,
    },
    {
      field: 'sql',
      label: 'SQL语句',
      component: 'ButtonCodeEditor',
      required: true,
      componentProps: {
        mode: MODE.SQL,
      },
      colProps: { span: 24, lg: 24, md: 24 },
    },
  ];
  if (componentType === ComponentTypeEnum.CheckboxGroup) {
    return checkboxItem;
  }
  return [
    {
      field: 'showColumn',
      label: '显示列',
      component: 'Input',
      required: true,
    },
    {
      field: 'primaryColumn',
      label: '主键列',
      component: 'Input',
      required: true,
    },
    {
      field: 'foreignKey',
      label: '外键列',
      component: 'Input',
    },
    {
      field: 'sql',
      label: 'SQL语句',
      component: 'CodeEditor',
      required: true,
      componentProps: {
        class: 'h-100 border-base',
        mode: MODE.SQL,
      },
      colProps: { span: 24, lg: 24, md: 24 },
    },

    {
      field: 'initCondition',
      label: '初始化条件',
      component: 'InputTextArea',
      colProps: { span: 24, lg: 24, md: 24 },
      componentProps: {
        rows: 2,
      },
    },
  ];
};

export const uploadSchema: FormSchema[] = [
  {
    field: 'primaryName',
    label: '主键名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'primaryCode',
    label: '主键编码',
    component: 'Input',
    required: true,
  },

  {
    field: 'foreignName',
    label: '外键名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'foreignCode',
    label: '外键编码',
    component: 'Input',
    required: true,
  },

  {
    field: 'serialNumberName',
    label: '排序字段',
    component: 'Input',
    required: true,
  },
  {
    field: 'serialNumberCode',
    label: '排序字段编码',
    component: 'Input',
    required: true,
  },

  {
    field: 'attachmentName',
    label: '文件名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'attachmentCode',
    label: '文件编码',
    component: 'Input',
    required: true,
  },
  {
    field: 'extName',
    label: '后缀名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'extCode',
    label: '后缀名编码',
    component: 'Input',
    required: true,
  },

  {
    field: 'tableName',
    label: '存储表名',
    component: 'Input',
    required: true,
  },

  {
    field: 'filePath',
    label: '文件存储路径',
    component: 'Input',
    required: true,
  },
  {
    field: 'storeRule',
    label: '存储规则',
    component: 'Input',
    required: true,
  },
  {
    field: 'storeType',
    label: '存储方式',
    component: 'RadioGroup',
    required: true,
    defaultValue: 1,
    componentProps: {
      options: StoreTypeList,
    },
  },
  {
    field: 'typeCode',
    label: '文件编码',
    component: 'Input',
  },
  {
    field: 'typeName',
    label: '文件类型',
    component: 'Input',
  },

  {
    field: 'limitCondition',
    label: '限制条件',
    component: 'Input',
  },
  {
    field: 'contentName',
    label: '文件描述',
    component: 'Input',
  },
  {
    field: 'contentCode',
    label: '文件描述编码',
    component: 'Input',
  },
  {
    field: 'extField',
    label: '扩展字段',
    component: 'Input',
  },
  {
    field: 'extFieldVal',
    label: '缺省值',
    component: 'Input',
  },
];
